package com.hgm.travelapp.fragment

import android.os.Bundle
import android.text.TextUtils
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.fragment.app.DialogFragment
import com.hgm.travelapp.R

/**
 * @author    HGM
 * @version   1.0
 */
class PwdDialog : DialogFragment() {
      private var flag = false
      private var click = 1

      override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)

      }

      override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
      ): View? {
            //绑定控件
            val view = inflater.inflate(R.layout.changepwd_dialog_fragment, container, false)
            val oldPwd = view.findViewById<TextView>(R.id.oldPwd)
            val ivWarn = view.findViewById<ImageView>(R.id.iv_warn)
            val tvWarn = view.findViewById<TextView>(R.id.tv_warn)
            val newPwd = view.findViewById<TextView>(R.id.newPwd)
            val ivWarn2 = view.findViewById<ImageView>(R.id.iv_warn2)
            val tvWarn2 = view.findViewById<TextView>(R.id.tv_warn2)
            val cancel = view.findViewById<Button>(R.id.btn_cancel)
            val sure = view.findViewById<Button>(R.id.btn_sure)
            view.findViewById<Button>(R.id.btn_sure)


            //点击事件
            cancel.setOnClickListener {
                  dismiss()
            }
            sure.setOnClickListener {
                  //判空
                  if (!TextUtils.isEmpty(oldPwd.text.toString().trim())) {
                        ivWarn.visibility = View.VISIBLE
                        tvWarn.visibility = View.VISIBLE
                        return@setOnClickListener
                  }
                  //进行第一次点击
                  if (click==1) {
                        ivWarn.visibility = View.GONE
                        tvWarn.visibility = View.GONE
                        //显示所有ui，修改密码
                        oldPwd.hint = "新密码"
                        oldPwd.text = ""
                        newPwd.visibility = View.VISIBLE
                        sure.text = "确定"
                        //【第一个框判断】

                  } else {

                  }
                  //dismiss()
                  //dialog?.cancel()
                  //TODO 修改密码的业务逻辑

            }
            return view
      }

      override fun onStart() {
            super.onStart()
            if (dialog != null) {
                  val metrics = resources.displayMetrics
                  //宽度设为屏幕宽度的90%
                  dialog!!.window?.setLayout(
                        (metrics.widthPixels * 0.9).toInt(),
                        ViewGroup.LayoutParams.WRAP_CONTENT
                  )
            }
      }

      override fun onActivityCreated(savedInstanceState: Bundle?) {
            super.onActivityCreated(savedInstanceState)

      }
}